﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web.Caching;
using Dazaza.Framework.Utility;

namespace Dazaza.Framework.Configuration
{
    public class ConfigMananger : ConfigurationManagerBase
    {
        private static WebSiteConfig _webSiteConfig;
        public static WebSiteConfig WebSiteConfig
        {
            get 
            {
                string key = "WebSiteConfig";
                _webSiteConfig = CacheHelperBase.GetByDependency<WebSiteConfig>(key);
                if (_webSiteConfig == null)
                {
                    string fileName = FolderOper.DummyToFact(ConfigurationManager.AppSettings[key]);
                    _webSiteConfig = LoadConfiguration<WebSiteConfig>(key, fileName, false);
                    CacheHelperBase.SetByDependency(key, _webSiteConfig, fileName);
                }
                return _webSiteConfig;
            }
        }

        private static RSConfig _rsConfig;
        public static RSConfig RSConfig
        {
            get
            {
                string key = "RSConfig";
                _rsConfig = CacheHelperBase.GetByDependency<RSConfig>(key);
                if (_rsConfig == null)
                {
                    string fileName = FolderOper.DummyToFact(ConfigurationManager.AppSettings[key]);
                    _rsConfig = LoadConfiguration<RSConfig>(key, fileName, false);
                    CacheHelperBase.SetByDependency(key, _rsConfig, fileName);
                }
                return _rsConfig;
            }
        }

        private static ParameterConfig _parameterConfig;
        public static ParameterConfig ParameterConfig
        {
            get
            {
                string key = "Parameters";
                _parameterConfig = CacheHelperBase.GetByDependency<ParameterConfig>(key);
                if (_parameterConfig == null)
                {
                    string fileName = FolderOper.DummyToFact(ConfigurationManager.AppSettings[key]);
                    _parameterConfig = LoadConfiguration<ParameterConfig>(key, fileName, false);
                    CacheHelperBase.SetByDependency(key, _parameterConfig, fileName);
                }
                return _parameterConfig;
            }
        }
        private static ConnectionConfig _connectionConfig;
        public static ConnectionConfig ConnectionConfig
        {
            get
            {
                string key = "Connection";
                _connectionConfig = CacheHelperBase.GetByDependency<ConnectionConfig>(key);
                if (_connectionConfig == null)
                {
                    string fileName = FolderOper.DummyToFact(ConfigurationManager.AppSettings[key]);
                    _connectionConfig = LoadConfiguration<ConnectionConfig>(key, fileName, false);
                    CacheHelperBase.SetByDependency(key, _connectionConfig, fileName);
                }
                return _connectionConfig;
            }
        }
       
    }
}
